<script setup >
import { ref, onMounted, watch } from 'vue'
import { reqList, reqTableList } from "../api";
const count = ref(0)
// const or = ref(true)
const i = ref([0, 0, 0, 0])
const listName = ref('')
const clickData = ref('')
//请求一级列表数据
async function reqListData() {
  const listData = await reqList()
  return listData
}
//请求表格数据
async function reqClickSelectData(page = 1, id) {
  const clickSelectData = await reqTableList(page, id)
  return clickSelectData
}
//储存展开状态
function unfold(index) {
  // or.value = !or.value
  // console.log(index)
  if (i.value[index] == 1) {
    i.value[index] = 0
    // console.log(i.value)
  } else {
    i.value[index] = 1
  }
}
//正常数据不会有重复的名字所以不会出现hover一列的情况
function over(e) {
  console.log(e.target.dataset.id)
  listName.value = e.target.dataset.id
}
function leave(e) {
  listName.value = ''
}
onMounted(() => {
  const data = reqListData()
  data.then((a) => {
    console.log(a.data.list)
    count.value = a.data.list
  })
})
// 表格的数据
function clickSelect(id) {
  console.log(id)
  reqClickSelectData(1, id).then((val) => {
    clickData.value = val.data.list
    console.log(clickData.value)
  })
}
</script>

<template>
  <!-- 头部 -->
  <div class="row">
    <div class="box-card1">
      <div class="box">
        <div class="box-left">
          <a href="" class="gcy">
            <img src="https://test.nttcc.com.cn/_nuxt/img/logo_1.e54ae31.png">
            <h1>共创云</h1>
          </a>
          <div class="head-list">
            <a href="" class="clear-margin">
              服务产品
            </a>
            <a href="">
              科创需求
            </a>
            <a href="">
              专利论文
            </a>
            <a href="">
              交易大数据
            </a>
          </div>
        </div>
        <div class="box-right">
          <el-button type="primary">登录</el-button>
          <el-button>注册</el-button>
        </div>
      </div>
    </div>
  </div>
  <!-- 内容部分 -->
  <div class="box-card2">
    <!-- 内容头 -->
    <div class="content-top">
      <div class="content-top-left">
        <img data-v-1887221e=""
          src=""
          alt="" style="margin-right: 16px;">
        <span>资源大厅</span>
      </div>
      <div class="mt-4">
        <el-input v-model="input2" placeholder="请输入资源名称或用户名搜索" style="width: 450px;height: 40px;">
          <template #append>
            <el-button type="primary" style="background-color: var(--color);height: 40px; color: white;">
              <el-icon style="color: white;padding: 0 5px;">
                <Search />
              </el-icon>
              搜索
            </el-button>
          </template>
        </el-input>
      </div>
    </div>
    <div class="content-center1">
      <span>服务</span>
      <span>需求</span>
      <span>科创资源</span>
    </div>
    <div class="content-center2">
      <!-- 内容一级列表 -->
      <!-- 没有找到完整的数据所以同一份数据用4次了 -->
      <div class="li" v-for="item, index in 4" :key="index">
        <div class="liItem">
          <div class="span">服务类型:</div>
          <div class="liItemList" :class="{ overflow: !i[index] }">
            <div v-for="item in count" @click="clickSelect(item.id)" @mouseleave="leave" @mouseover="over"
              :data-id="item.name" :class="{ listHover: listName === item.name, divList: true }">{{ item.name }}</div>
          </div>
          <div class="gengduo" v-if="!i[index]" @click="unfold(index)" :key="item.id">
            <div class="text">更多</div>
            <el-icon>
              <ArrowDown />
            </el-icon>
          </div>
          <div class="gengduo" v-if="i[index]" @click="unfold(index)" :key="item.id">
            <div class="text">收起</div>
            <el-icon>
              <ArrowUp />
            </el-icon>
          </div>
        </div>
      </div>
    </div>
    <!-- 内容表格 -->
    <!-- 头 -->
    <div class="table">
      <table class="tb">
        <tr class="tableHead">
          <td>服务名称</td>
          <td>发布用户</td>
          <td>服务类型</td>
          <td>成功成交数</td>
          <td>信用评价</td>
        </tr>
        <tr v-for="item in clickData">
          <td>{{ item.title }}</td>
          <td>{{ item.orgName }}</td>
          <td>{{ item.serviceTypeName }}</td>
          <td>{{ item.avgScore }}</td>
          <td>{{ item.platformScore }}</td>
        </tr>
      </table>
    </div>
  </div>
  <div>
    <hr style="border: 0;">
  </div>
</template>

<style scoped lang="less">
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}

.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.row {
  width: 100%;
  background-color: white;

  .box-card1 {
    width: 1200px;
    box-sizing: border-box;
    margin: 0 auto;
    // display: flex;
    // justify-content: space-between;


    .box {
      width: 1200px;
      height: 50px;
      display: flex;
      justify-content: space-between;
      align-items: center;

      .box-left {
        width: 470px;
        height: 30px;
        display: flex;
        justify-content: space-between;

        .gcy {
          display: flex;
          justify-content: space-between;
          align-items: center;

          img {
            width: 30px;
            height: 30px;
            margin-right: 10px;
          }

          h1 {
            font-size: 16px;
            margin-right: 50px;
            color: var(--color);
          }
        }

        .head-list {
          font-size: 14px;
          line-height: 30px;
          flex: 1;

          a {
            margin-left: 24px;
          }
        }
      }
    }
  }
}

// 下面是自己写的样式，上面是elementPlus的样式
.box-card2 {
  width: 1200px;
  margin: 30px auto;
  padding: 30px;
  background-color: white;
  display: flow-root;

  .content-top {
    width: 1200px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;

    .content-top-left {
      width: 104px;
      height: 40px;
      display: flex;
      align-items: center;

      span {
        font-weight: 700;
      }
    }
  }

  .content-center1 {
    width: 1140px;
    height: 48px;
    line-height: 48px;
    padding: 0 30px;
    margin-bottom: 10px;
    font-size: 14px;
    font-weight: 700;
    float: left;
    color: #303133;
    background-color: #f7f8f9;

    span {
      margin-right: 140px;
    }

    span:hover {
      color: var(--color);
      border-bottom: 2px solid #3473e6;
    }
  }

  .content-center2 {
    width: 1158px;
    // height: 204px;
    padding: 0 20px;
    border: 1px solid #dcdfe6;
    border-radius: 5px;
    display: flow-root;

    .li {
      width: 100%;

      // height: 50px;
      // overflow: hidden;
      // line-height: 50px;
      .liItem {
        // height: 50px;
        // line-height: 50px;
        display: flex;
        justify-content: space-between;
        align-items: start;

        .span {
          width: 120px;
          height: 50px;
          line-height: 50px;
          color: #909399;
          font-size: 14px;
        }

        .liItemList {
          flex: 0.8;
          margin-left: -100px;

          // height: 50px;
          // overflow: hidden;
          .divList {
            height: 50px;
            line-height: 50px;
            margin-right: 25px;
            float: left;
            text-align: center;
            font-size: 14px;
            color: #303133;
          }
        }

        .gengduo {
          width: 50px;
          display: flex;
          margin-top: 12px;

          .text {
            width: 30px;
            font-size: 14px;
            color: var(--color);
          }
        }
      }
    }
  }

  .tb {
    width: 1200px;
  }
}

.overflow {
  height: 50px;
  overflow: hidden;
}

.listHover {
  color: white !important;
  background-color: var(--color);
}
</style>
